package thread2;

public class LambdaDemo {
    /**
     * 静态内部类
     */
    static class Like2 implements ILike {
        @Override
        public void lambda() {
            System.out.println("i like lambda2");
        }
    }

    public static void main(String[] args) {
        ILike like = new Like();
        like.lambda();

        ILike like2 = new Like2();
        like2.lambda();

        /*
        局部内部类
         */
        class Like3 implements ILike {
            @Override
            public void lambda() {
                System.out.println("i like lambda3");
            }
        }

        ILike like3 = new Like3();
        like3.lambda();

        /*
        匿名内部类：没有类的名称，必须通过接口或者父类实现
         */
        like = new ILike() {
            @Override
            public void lambda() {
                System.out.println("i like lambda4");
            }
        };

        like.lambda();

        /*
        lambda表达式
         */
        like = () -> System.out.println("i like lambda5");
        like.lambda();
    }
}

/**
 * 函数式接口
 */
interface ILike {
    void lambda();
}

/**
 * 普通实现类
 */
class Like implements ILike {

    @Override
    public void lambda() {
        System.out.println("i like lambda");
    }
}